﻿@inherits SsoCompontentBase
@inject EnvironmentDataService EnvironmentData

<div class="d-flex flex-column mb-12">
    <div class="d-flex block-center mt-8 mb-4 mx-12">
        <div style="background: #E9EDF7;height: 1px;width: 100%;" />
        <div class="mx-4 text-center body2 neutral-lighten-4--text" style="@(LanguageProvider.Culture.ToString() == "zh-CN"?"min-width:120px":"min-width:100px")">@T("or login with")</div>
        <div style="background: #E9EDF7;height: 1px;width: 100%;" />
    </div>
    <div class="text-center">
        @foreach (var externalProvider in ExternalProviderList)
        {
            <MAvatar Size="30" Class="hover-pointer mx-3">
                <img src="@externalProvider.Icon" @onclick="() => NavigateToThirdParty(externalProvider.AuthenticationScheme)" />
            </MAvatar>
        }
    </div>
</div>

@code {
    [EditorRequired]
    [Parameter]
    public string ReturnUrl { get; set; } = string.Empty;

    [EditorRequired]
    [Parameter]
    public IEnumerable<ViewModel.ExternalProvider> ExternalProviderList { get; set; } = Enumerable.Empty<ViewModel.ExternalProvider>();

    private void NavigateToThirdParty(string scheme)
    {
        var challenge = QueryHelpers.AddQueryString(AuthenticationExternalConstants.ChallengeEndpoint, new Dictionary<string, string?>
            {
                ["returnUrl"] = ReturnUrl,
                ["scheme"] = scheme,
                ["environment"] = EnvironmentData.Environment
            });
        Navigation.NavigateTo(challenge, true);
    }
}
